<template>
  <a-card :bordered="false">
   <div class="table-page-search-wrapper">
         <a-form layout="inline" @keyup.enter.native="searchQuery">
           <a-row :gutter="24">
             <a-col :xl="6" :lg="7" :md="8" :sm="24">
               <a-form-item label="纳税人识别号">
                 <j-input placeholder="请输入纳税人识别号" v-model="queryParam.creditCode"></j-input>
               </a-form-item>
             </a-col>
             <a-col :xl="6" :lg="7" :md="8" :sm="24">
               <a-form-item label="个体户姓名">
                 <j-input placeholder="请输入个体户姓名" v-model="queryParam.traname"></j-input>
               </a-form-item>
             </a-col>
             <a-col :xl="6" :lg="7" :md="8" :sm="24">
               <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                 <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                 <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
               </span>
             </a-col>
           </a-row>
         </a-form>
       </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"

        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleError(record.id, 0)" v-if="record.status == 3">退回待开</a>
          <a-divider type="vertical" v-if="record.status == 3" />
          <a @click="handleError(record.id, 1)" v-if="record.status == 3">重新查询</a>
        </span>

      </a-table>
    </div>

    <lhyg-reg-invoice-modal ref="modalForm" @ok="modalFormOk"></lhyg-reg-invoice-modal>
  </a-card>
</template>

<script>

  import { httpAction, getAction, postAction } from '@/api/manage'
  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import LhygRegInvoiceModal from './modules/LhygRegInvoiceModal'
  import JInput from '@/components/jeecg/JInput'
  import JEllipsis from '@/components/jeecg/JEllipsis'

  export default {
    name: 'LhygRegInvoiceList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      LhygRegInvoiceModal,JInput,JEllipsis,
    },
    data () {
      let ellipsis = (v,l=20) => (<j-ellipsis value={v} length={l}/>)
      return {
        description: '个人给平台开票的发票主表管理页面',
        // 表头
        columns: [
          {
             title:'申请单号',
             align:"center",
             dataIndex: 'orderNo'
          },
          {
             title:'个体户姓名',
             align:"center",
             dataIndex: 'traname'
           },
          {
            title:'纳税人识别号',
            align:"center",
            dataIndex: 'creditCode'
          },
          {
            title:'货物或应税劳务、服务名称',
            align:"center",
            dataIndex: 'goodsName'
           },
           {
            title:'开票金额',
            align:"center",
            dataIndex: 'invoiceJe'
          },
          {
            title:'当前是否超定额',
            align:"center",
            customRender:function (text,record,index) {
                if(record.invoiceJe>40000){
                   return  '是'
                }else{
                   return '否'
                }
              }
          },
          {
            title:'当前待开票金额',
            align:"center",
            customRender:function (text,record,index) {
                 return record.invoiceJe
            }
          },
          {
             title:'申请时间',
             align:"center",
             dataIndex: 'createTime',
             customRender:function (text) {
                return !text?"":(text.length>10?text.substr(0,10):text)
             }
           },
          {
            title:'返回信息',
            align:"left",
            dataIndex: 'message',
            customRender: (text) => ellipsis(text)
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/gsinvoice/lhygRegInvoice/kjlist",
          delete: "/gsinvoice/lhygRegInvoice/delete",
          deleteBatch: "/gsinvoice/lhygRegInvoice/deleteBatch",
          exportXlsUrl: "/gsinvoice/lhygRegInvoice/exportXls",
          importExcelUrl: "gsinvoice/lhygRegInvoice/importExcel",
          handleError: "/gsinvoice/lhygRegInvoice/handleError",

        },
        dictOptions:{},
      }
    },
    created() {
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      handleError(id, status) {
        const that = this;
        let formData=new FormData();
        formData.append('id', id);
        formData.append('status', status);
        postAction(this.url.handleError, formData).then((res)=>{
          if (res.success) {
            that.$message.success(res.message);
            this.onClearSelected();
            this.loadData();
          } else {
            that.$message.warning(res.message);
          }
        })
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>


